package com.orange.wwwapi.controller.carpark;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.carpark.CarParkOrder;
import com.orange.core.pojo.req.carpark.CarParkOrderPageReq;
import com.orange.core.service.carpark.CarParkOrderService;
import com.orange.core.util.PrincipalUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 停车订单
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/carParkOrder")
public class CarParkOrderController {

    private final CarParkOrderService carParkOrderService;

    /**
     * 分页
     */
    @PostMapping("/page")
    public R<Page<CarParkOrder>> page(@RequestBody PageReqDto<CarParkOrderPageReq> dto) {
        if (dto.getCondition() == null) {
            dto.setCondition(new CarParkOrderPageReq());
        }
        return R.ok(carParkOrderService.page(dto, PrincipalUtil.getId()));
    }

    /**
     * 详情
     */
    @GetMapping("/info/{id}")
    public R<CarParkOrder> info(@PathVariable("id") int id) {
        return R.ok(carParkOrderService.info(id));
    }
}
